package com.hspedu.newData.面试题;

import com.hspedu.newData.dmsxl.ds.ListNode;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-22 
 * @Version: 1.0
 */

public class LC0202返回倒数第k个节点 {

    public int kthToLast(ListNode head, int k) {

        ListNode dummy = new ListNode(0,head);

        ListNode fast = dummy.next;
        ListNode slow = dummy.next;

        int i = 0;
        while (i<k){
            fast = fast.next;
            i++;
        }

        while (fast != null){
            fast = fast.next;
            slow = slow.next;
        }

        return slow.next.val;

    }

}
